#!/bin/sh
#
# Run a simple backup  then migrate it
#   to another device.
#
# This script uses the virtual disk autochanger
#
TestName="migration-occupancy-test"
JobName=MigrationJobSave
. scripts/functions


scripts/cleanup
scripts/copy-migration-confs
scripts/prepare-disk-changer

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list



change_jobname NightlySave $JobName
start_test

#
# Note, we first backup into Pool Default,
#          then Migrate into Pool Full.
#              Pool Default uses Storage=File
#              Pool Full    uses Storage=DiskChanger

# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=FileVolume001 Pool=Default
label storage=DiskChanger volume=ChangerVolume001 slot=1 Pool=Full drive=0
label storage=DiskChanger volume=ChangerVolume002 slot=2 Pool=Full drive=0
list volumes
@# run two jobs (both will be migrated)
run job=$JobName yes
run job=$JobName yes
wait
update volume=FileVolume001 VolStatus=Used
list volumes
@# should migrate two jobs
run job=migrate-occupancy yes
list volumes
wait
messages
purge volume=FileVolume001
wait
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/susan-restores select storage=DiskChanger
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=File
stop_susan

check_two_logs
check_restore_diff
end_test
